package com.longrise.android.byjk.plugins.vip.dailysign;

import android.graphics.Color;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.R;
import com.longrise.android.byjk.widget.view.RoundImageView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by callxkj on 2017/4/18.
 * 每日签到
 */

public class DailySignRcvAdapter extends BaseQuickAdapter<EntityBean, BaseViewHolder> {

    private List<EntityBean> mListBeans = new ArrayList<>();

    public DailySignRcvAdapter() {
        super(R.layout.item_dailysign_rcv);
    }

    public void refreshData(EntityBean[] rankbeans) {
        for (int x = 0; x < rankbeans.length; x++) {
            EntityBean rankbean = rankbeans[x];
            mListBeans.add(rankbean);
        }
        setNewData(mListBeans);
    }

    @Override
    protected void convert(BaseViewHolder helper, EntityBean item) {
        View convertView = helper.getConvertView();
        int layoutPosition = helper.getLayoutPosition();
        RoundImageView headicon = (RoundImageView) convertView.findViewById(R.id.item_dailysign_rank_headicon);
        headicon.setBorderColor(Color.WHITE);
        TextView tv_days = (TextView) convertView.findViewById(R.id.item_dailysign_rank_lxqd_days);
        TextView tv_qian = (TextView) convertView.findViewById(R.id.item_dailysign_rank_lxqd_qian);
        String updatetime = item.getString("updatetime"); //签到更新时间
        if (!TextUtils.isEmpty(updatetime) && updatetime.length() >= 19) {
            updatetime = updatetime.substring(11, 19);
        }
        String continuitydays = item.getString("continuitydays"); //连续签到天数
        String nickname = item.getString("nickname"); //昵称
        String userheadurl = item.getString("userheadurl"); //头像
        String companyname = TextUtils.isEmpty(item.getString("companyname")) ? " " : item.getString("companyname"); //所属公司
        String managerzonename = TextUtils.isEmpty(item.getString("managerzonename")) ? " " : item.getString("managerzonename"); //管辖区域

        Glide.with(mContext).load(userheadurl).error(R.drawable.default_pic).into(headicon);
        helper.setText(R.id.item_dailysign_rank_name, nickname);
        helper.setText(R.id.item_dailysign_rank_company, managerzonename + " " + companyname);
        helper.setText(R.id.item_dailysign_rank_lxqd_days, continuitydays);
        helper.setText(R.id.item_dailysign_rank_time, updatetime);
        switch (layoutPosition) {
            case 0:
                tv_qian.setTextColor(Color.parseColor("#FF8B4C"));
                tv_days.setTextColor(Color.parseColor("#FF8B4C"));
                tv_days.setTextSize(TypedValue.COMPLEX_UNIT_SP, 32);
                helper.setVisible(R.id.item_dailysign_rank_tv, false);
                helper.setVisible(R.id.item_dailysign_rank_iv, true);
                helper.setImageResource(R.id.item_dailysign_rank_iv, R.drawable.ic_ranking_no1);
                break;
            case 1:
                tv_qian.setTextColor(Color.parseColor("#FF8B4C"));
                tv_days.setTextColor(Color.parseColor("#FF8B4C"));
                tv_days.setTextSize(TypedValue.COMPLEX_UNIT_SP, 32);
                helper.setVisible(R.id.item_dailysign_rank_tv, false);
                helper.setVisible(R.id.item_dailysign_rank_iv, true);
                helper.setImageResource(R.id.item_dailysign_rank_iv, R.drawable.ic_ranking_no2);
                break;
            case 2:
                tv_qian.setTextColor(Color.parseColor("#FF8B4C"));
                tv_days.setTextColor(Color.parseColor("#FF8B4C"));
                tv_days.setTextSize(TypedValue.COMPLEX_UNIT_SP, 32);
                helper.setVisible(R.id.item_dailysign_rank_tv, false);
                helper.setVisible(R.id.item_dailysign_rank_iv, true);
                helper.setImageResource(R.id.item_dailysign_rank_iv, R.drawable.ic_ranking_no3);
                break;
            default:
                tv_qian.setTextColor(Color.parseColor("#66CAFF"));
                tv_days.setTextColor(Color.parseColor("#66CAFF"));
                tv_days.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
                helper.setVisible(R.id.item_dailysign_rank_tv, true);
                helper.setVisible(R.id.item_dailysign_rank_iv, false);
                helper.setText(R.id.item_dailysign_rank_tv, (layoutPosition + 1) + "");
                break;
        }

    }

}
